/**
 * Created by JustinChow on 2016/11/14.
 */

"use strict";

require("../Utils/Methematics");

/**
 * Random A Tank Move Packet
 * @returns {{rotation: number, radian: number, x: *, y: *}}
 */
function randTankTarget (){
    var rand = Math.random();
    var nagtive = Math.floor(rand * 10) % 2 ? -1 : 1;
    var v = Math.RadianToXY(nagtive * rand * Math.PI);
    return {
        "rotation": Math.floor(nagtive * rand * 180), // ±180°
        "radian": nagtive * rand * Math.PI, // ±π
        "x":  v.x, // 0-maxW
        "y": v.y   // 0-maxH
    };
}


const Logger = require("pomelo-logger").getLogger("BotPlayer", __filename);

const PlayerTracker = require("../Classes/PlayerTracker");

const Vector = require("../Utils/Vector");

function BotPlayer(gameServer, socket) {
    PlayerTracker.apply(this, Array.prototype.slice.call(arguments));

    // Extend From Base Class PlayerTracker
    // this.gameServer = gameServer;
    // this.socket = socket;

    this.objectId = 0;

    this.moveTick = 0;
}

module.exports = BotPlayer;
BotPlayer.prototype = new PlayerTracker();

BotPlayer.prototype.update = function () {
    // Move
    this.moveTick += 1;
    if (this.moveTick % 25 === 0) {
        var nextTarget = randTankTarget();
        this.setTarget(nextTarget.rotation, nextTarget.radian, nextTarget.x, nextTarget.y);
    }
};
